package my.iterator;

import lombok.Data;

import java.util.Iterator;

//餐厅菜单
@Data
public class DinerMenu implements Menu {

    //菜单最大长度
    static final int MAX_ITEMS = 6;
    private int numberOfItems = 0;
    private MenuItem[] menuItems;

    public DinerMenu() {
        menuItems = new MenuItem[MAX_ITEMS];
        addItem("小鸡炖蘑菇", "东北小鸡", false, 40.8);
        addItem("猪肉炖粉条", "农家土猪", false, 50.9);
        addItem("大米饭", "铁力大米", true, 1);
    }

    public void addItem(String name, String description, boolean vegetarian, double price) {
        if (numberOfItems >= MAX_ITEMS) {
            System.out.println("菜单已经满了");
        } else {
            MenuItem menuItem = new MenuItem(name, description, vegetarian, price);
            menuItems[numberOfItems++] = menuItem;
        }
    }

    @Override
    public Iterator createIterator() {
        return new DinerMenuIterator(menuItems);
    }

}
